package com.yq.ylmall.search.document;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.math.BigDecimal;
import java.util.List;

@ToString
@Data
@ApiModel(description = "商品检索模型")
@Document(indexName = "product")
public class ProductDocument {

    @ApiModelProperty(value = "商品ID")
    @Id
    @Field(type = FieldType.Long)
    private Long id;

    @ApiModelProperty(value = "商品名称")
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String productName;

    @ApiModelProperty(value = "权重排序")
    @Field(type = FieldType.Integer)
    private Integer sort;

    @ApiModelProperty(value = "商品描述")
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String productDesc;

    @ApiModelProperty(value = "售价")
    @Field(type = FieldType.Keyword)
    private BigDecimal salePrice;

    @ApiModelProperty(value = "市场价")
    @Field(type = FieldType.Keyword)
    private BigDecimal marketPrice;

    @ApiModelProperty(value = "折扣")
    @Field(type = FieldType.Double)
    private Double discount;

    @ApiModelProperty(value = "销量")
    @Field(type = FieldType.Integer)
    private Integer saleNum;

    @ApiModelProperty(value = "库存量")
    @Field(type = FieldType.Keyword)
    private Integer stockNum;

    @ApiModelProperty(value = "是否有库存")
    @Field(type = FieldType.Boolean)
    private Boolean hasStock;

    @ApiModelProperty(value = "品牌ID")
    @Field(type = FieldType.Long, index = false, docValues = false)
    private Long brandId;

    @ApiModelProperty(value = "品牌名称")
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String brandName;

    @ApiModelProperty(value = "轮播图地址")
    @Field(type = FieldType.Keyword, index = false, docValues = false)
    private String sliderUrls;

    @ApiModelProperty(value = "详情图片地址")
    @Field(type = FieldType.Keyword, index = false, docValues = false)
    private String imageUrls;

    @ApiModelProperty(value = "评论数量")
    @Field(type = FieldType.Integer)
    private Integer commentCount;

    @ApiModelProperty(value = "sku列表")
    @Field(type = FieldType.Nested)
    private List<ProductSkuDocument> skuList;

    @Data
    public static class ProductSkuDocument {

        @ApiModelProperty(value = "SkuID")
        @Id
        @Field(type = FieldType.Long)
        private Long skuId;

        @ApiModelProperty(value = "Sku名称")
        @Field(type = FieldType.Text, analyzer = "ik_max_word")
        private String skuName;

        @ApiModelProperty(value = "SkuCode")
        @Field(type = FieldType.Keyword, index = false, docValues = false)
        private String skuCode;

        @ApiModelProperty(value = "售价")
        @Field(type = FieldType.Keyword)
        private BigDecimal salePrice;

        @ApiModelProperty(value = "市场价")
        @Field(type = FieldType.Double, docValues = false)
        private BigDecimal marketPrice;

        @ApiModelProperty(value = "销量")
        @Field(type = FieldType.Integer)
        private Integer saleNum;

        @ApiModelProperty(value = "库存量")
        @Field(type = FieldType.Keyword)
        private Integer stockNum;

        @ApiModelProperty(value = "是否有库存")
        @Field(type = FieldType.Boolean)
        private Boolean hasStock;

        @ApiModelProperty(value = "缩略图路径")
        @Field(type = FieldType.Keyword, index = false, docValues = false)
        private String thumbImg;

        @ApiModelProperty(value = "sku规格信息")
        @Field(type = FieldType.Keyword, index = false, docValues = false)
        private String skuSpec;

        @ApiModelProperty(value = "重量")
        @Field(type = FieldType.Double, index = false, docValues = false)
        private Double weight;

        @ApiModelProperty(value = "体积")
        @Field(type = FieldType.Double, index = false, docValues = false)
        private Double volume;

    }

}
